package com.xspace.android.imcommon.message;

import android.content.Context;
import android.os.RemoteException;

import com.xspace.android.imcommon.db.FriendDb;
import com.xspace.android.imcommon.entity.Friend;
import com.xspace.android.imcommon.interfaces.FriendAidl;
import com.xspace.android.imcommon.interfaces.FriendCallback;
import com.xspace.android.imcommon.interfaces.FriendListAidl;
import com.xspace.android.imcommon.interfaces.FriendMapAidl;

import java.util.ArrayList;
import java.util.HashMap;

public class FriendManager {
	private FriendDb mFriendDb;

	public FriendManager(Context mContext) {
		this.mFriendDb = new FriendDb(mContext);
	}

	public void queryMapFriend(String userId, FriendCallback mFriendCallback){
		HashMap<String, Friend> map =mFriendDb.queryFriendMap(userId);
		try {
			mFriendCallback.onToFriendMap(new FriendMapAidl(map));
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void queryListFriend(String userId, FriendCallback mFriendCallback){
		ArrayList<Friend> dataList = mFriendDb.findList(userId);
		try {
			mFriendCallback.onToFriendList(new FriendListAidl(dataList));
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void queryFriend(String owner,String userId, FriendCallback mFriendCallback) {
		Friend friend =mFriendDb.queryFriends(owner, userId);
		try {
			mFriendCallback.onToFriend(new FriendAidl(friend));
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void saveOrUpdateFriend(FriendAidl info, String userId){
		mFriendDb.insertOrUpdateMsg(info.info, userId);
	}

	

}
